package com.zzx.day57Demo.DAO.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.context.annotation.Scope;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.zzx.day57Demo.DAO.ExpectDAO;
import com.zzx.day57Demo.model.Expect;

@Repository("expectDAO")
@Scope("prototype")
@SuppressWarnings("deprecation")
public class ExpectDAOImpl extends HibernateDaoSupport implements ExpectDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<Expect> findAll() {
		return (List<Expect>) getHibernateTemplate().executeFind(new HibernateCallback<List<Expect>>() {

			@Override
			public List<Expect> doInHibernate(Session session) throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				return session.createCriteria(Expect.class).setFetchMode("exp", FetchMode.JOIN).list();
			}
		});

	}

	
//	@Override
//	public void save(Expect exp) {
//		getHibernateTemplate().save(exp);
//		
//	}

	public void saveOrUpdate(Expect exp){
		getHibernateTemplate().saveOrUpdate(exp);
	}

	public void delete(Expect exp){
		getHibernateTemplate().delete(exp);
	}
	public Expect findById(int expId){
		
		return getHibernateTemplate().get(Expect.class, expId);
	}
	
}
